package club.baimahu.pencil.miaosha.controller;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;


/**
 * 操作日志记录处理
 * 
 * @author
 */
@Aspect
@Component
public class TimerAspect implements InitializingBean
{
    private static final Logger log = LoggerFactory.getLogger(TimerAspect.class);

    // 配置织入点
    @Pointcut("@annotation(club.baimahu.pencil.annotation.Timer)")
    public void timerPointCut()
    {

    }

    /**
     * 处理完请求后执行
     *
     * @param joinPoint 切点
     */
    @Around(value = "timerPointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

        long start = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        long end = System.currentTimeMillis();

        log.info("Timer切面方法[{}]耗时{}ms",joinPoint.getSignature().getName(),end-start);

        return result;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.debug("timerPointCut init");
    }
}
